(function($){
    $.fn.wtSetOn = function(options){
        options = $.extend({},{
            onStateClass:'on',
            onComplete:function(){}
        },options);

        var url = location.pathname.substring(1);

        return this.each(function(){
            var $holder=$(this);
            $holder.find('a[href*="' + url + '"]').addClass(options.onStateClass);

            if($holder.find('a[href*="' + url + '"]').size()==0){
                var path = url.split('/');
                var loc = path.pop().split('-')[0];
                var find = '/'+path.join('/')+'/'+loc+'-';
                $holder.find('a[href*="' + find + '"]').addClass('on selected');

                if($holder.find('a[href*="' + find + '"]').size()==0){
                    var path = url.split('/');
                    while(path.length>1 && path.pop()) {
                        $holder.find('a[href*="' + path.join('/') + '/"]').addClass('on selected');
                    }
                }
            }
            options.onComplete();
        });
    }
})(jQuery);
